{include file="Public:header" /}
<style>
    .pagination a {
        background-color: #f4f4f4;
        z-index: 2;
        border: 1px solid #000;
        border-color: rgb(221, 221, 221);
        padding: 4px 10px;
        margin: 0px 3px;
        border-radius: 10%;
    }

    .select_no_border{
        border-right: none;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>答题信息列表</h5>
                    <div class="ibox-tools" style="margin-top: -6px;">
                        <a href="__MODULE__/{$Think.CONTROLLER_NAME}/{$Think.ACTION_NAME}" class="btn btn-primary"><i class="fa fa-refresh"></i> 刷新</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <!--<div class="col-sm-3" style="width: 20%;">
                            &lt;!&ndash;<a href="__URL__/addQuestion" class="btn btn-primary">
                                <span class="fa fa-plus"></span>
                                添加题库
                            </a>&ndash;&gt;
                        </div>-->
                        <form class="form-inline" action="__URL__/answerInfoList" method="get">
                            <div class="col-sm-12">
                                <div class="input-group col-sm-4  pull-right" style="width: 300px;">
                                    <input type="text" name="username" placeholder="请输入用户名" value="{:I('username')}" class="input-sm form-control">
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                                    </span>
                                </div>

                                <div class="input-group col-sm-2 pull-right">
                                    <input type="text" name="school" value="{:I('school')}" placeholder="请输入学校名称" class="input-sm form-control select_no_border">
                                </div>

                                <div class="input-group col-sm-2 pull-right">
                                    <select name="area" id="area" class="input-sm form-control select_no_border">
                                        <option value="0">请选择区/县</option>
                                        <!--处理第一次只选市搜索后再点区的情况-->
                                        {volist name="areadata" id="vo"}
                                        <option label="{$vo.name}"  value="{$vo.name}" >{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>

                                <div class="input-group col-sm-2 pull-right">
                                    <select name="city" id="city" onchange="loadRegion('city',3,'area','{:U('Answer/getRegion')}');" class="input-sm form-control select_no_border">
                                        <option value="0">请选择城市</option>
                                        {volist name="province" id="vo"}
                                            <option {if condition="$vo.id eq $city"}selected{/if} value="{$vo.name}_{$vo.id}" >{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                        </form>
                    </div>

                    <br/>
                    <div class="table-responsive">
                        <form id="allDelForm" action="__URL__/deleteAllInfo" method="post">
                            <table class="table table-bordered table-hover"
                                   id="categoryTable">
                                <thead>
                                <tr class="active">
                                    <th width="50px"><input onclick="choosebox(this)" type="checkbox"/></th>
                                    <th width="100px" height="40">ID</th>
                                    <th>用户名</th>
                                    <th>地区</th>
                                    <th>学校</th>
                                    <th>得分</th>
                                    <th>答题用时</th>
                                    <!--<th>奖励积分</th>-->
                                    <th>答题时间</th>
                                    <th width="100px">操作</th>
                                </tr>
                                </thead>

                                <tbody>
                                {volist name="data" id="vo"  key="k"}
                                <tr>
                                    <td><input type="checkbox" name="id[]" value="{$vo['id']}"/></td>
                                    <!--<td>{$k + ($p - 1) * $perCount}</td>-->
                                    <td>{$vo['id']}</td>
                                    <td>{$vo['nickname']}</td>
                                    <td>{$vo['city']}{$vo['area']}</td>
                                    <td>{$vo['school']}</td>
                                    <td>{$vo['score']}</td>
                                    <td>{$vo['total_time']}秒</td>
                                    <!--<td>{$vo['jifen']}</td>-->
                                    <td>{$vo['add_time']|date="Y-m-d H:i:s",###}</td>
                                    <td class="center">
                                        <div class="dropdown">
                                            <button class="btn btn-primary dropdown-toggle"
                                                    type="button" id="dropdownMenu1" data-toggle="dropdown"
                                                    aria-haspopup="true" aria-expanded="true">
                                                操作
                                                <span class="caret"></span>
                                            </button>
                                            <ul style="min-width: 90px;" class="dropdown-menu" aria-labelledby="dropdownMenu1">
                                                <li>
                                                    <a role="button" class="btn btn-primary"
                                                       style="margin-bottom: 0px;"
                                                       href="__URL__/answerInfoEdit?id={$vo['id']}">
                                                        <span class="fa fa-edit"></span>
                                                        修改
                                                    </a>
                                                </li>
                                                <li>
                                                    <a role="button" class="btn btn-danger"
                                                       style="margin-bottom: 0px;"
                                                       onclick="deleteQuestion(this,{$vo['id']})">
                                                        <span class="fa fa-trash-o"></span>
                                                        删除
                                                    </a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>

                        </form>
                        <div style="padding-left:0px;" class="col-sm-3 text-left">
                            <button id="allDel" class="btn btn-danger">删除</button>
                        </div>
                        <div class="col-sm-12 text-center">
                            <nav aria-label="Page navigation">
                                <ul class="pagination">
                                    {$page}
                                </ul>
                            </nav>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer" /}
<script>
    var area = "{$area}";
    $(document).ready(function () {
        //选中区状态
        if(Number(area) != 0)
        {
            $("#area option").each(function(){
                if($(this).attr('label') == area){
                    $(this).attr("selected",true);
                }
            });
        }
    });
</script>

<script>
    function choosebox(o) {
        var vt = $(o).is(':checked');
        if (vt) {
            $('input[type=checkbox]').prop('checked', vt);
        } else {
            $('input[type=checkbox]').removeAttr('checked');
        }
    }
</script>

<script>
    //删除
    function deleteQuestion(obj, id) {
        layer.confirm('确定要删除数据吗', {btn: ['确认', '取消'], icon: 3, closeBtn: 2}, function (index) {
            $.ajax({
                url: '__URL__/answerInfoDel',
                data: {'id': id},
                type: 'get',
                dataType: 'json',
                async: false,   //取消同步，执行完之后再往下执行
                success: function (data) {
                    if (data.status == 1) {
                        layer.msg('' + data.message + '', {icon: 2, time: 1000});
                        $(obj).parent('li').parent('ul').parent('div').parent('td').parent('tr').remove();
                    } else if (data.status == 2) {
                        layer.msg('' + data.message + '', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }

   $("#allDel").click(function () {
       layer.confirm('确定要删除数据吗', {btn: ['确认', '取消'], icon: 3, closeBtn: 2}, function (index) {
           $("#allDelForm").submit();
       });
   });

    function loadRegion(sel,type_id,selName,url){
        //alert(123)
       var p_id = jQuery("#"+sel).val();
        var idarray = p_id .split("_");

        jQuery("#"+selName+" option").each(function(){
            jQuery(this).remove();
        });

        if (type_id ==3)
            jQuery("<option value=0>请选择区/县</option>").appendTo(jQuery("#"+selName));

        //没选择
        if(jQuery("#"+sel).val() ==0){
            return;
        }
        //return false;
        jQuery.getJSON(url,{pid:idarray[1],type:type_id},
            function(data){
                if(data){
                    jQuery.each(data,function(i,item){
                        jQuery("<option  value="+item.name+">"+item.name+"</option>").appendTo(jQuery("#"+selName));
                    });
                }else{
                    jQuery("<option value='0'>请选择</option>").appendTo(jQuery("#"+selName));
                }
            }
        );
    }
</script>
</body>
</html>
